package com.aseo.business.hibernate;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.hibernate.Accion;

@Service(value="com.aseo.business.hibernate.AccionManager")
public class AccionManager implements ManagerInterface<Accion>  {

	protected AccionManager(){
		
	}
	
	@Resource  
	private Dao dao;
	
	public void persist(Accion accion) {
		dao.persist(accion);
	}

	public List<Accion> getAll() {  
		final List<Accion> list = dao.find(Accion.class);  
	    return list;
	}
	
	public Accion get(Long idAccion) {
		return dao.get(Accion.class, idAccion);
	}
	
	public void validate(Accion accion) throws ConstraintViolationException {

		Set<ConstraintViolation<Accion>> constraintViolations = dao.validate(accion);
		
		for (ConstraintViolation<Accion> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation.getMessage());
		}
		
	}

}